package com.itheima.admin.mapper;

import com.itheima.pojo.pojo.User;
import com.itheima.pojo.vo.RoleUserVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from ss_user where user_id=#{id}")
    User selectById(String id);

    @Delete("delete from ss_user where user_id=#{id}")
    Boolean deleteById(String id);

    @SelectKey(statement = "SELECT UUID()",
            before = true,keyProperty = "userId",keyColumn = "user_id",resultType = String.class)
    @Insert("insert into ss_user(user_id,email,password,user_name,dept_id,gender,state,birthday," +
            "join_date,telephone)" +
            " values(UUID(),#{email},#{password},#{userName}" +
            ",#{deptId},#{gender},#{status},#{birthday}" +
            ",#{joinDate},#{telephone}" +
            ")")
    Boolean addUser(User user);

    @Update("update ss_user set email=#{email},password=#{password},user_name=#{userName}," +
            "dept_id=#{deptId},gender=#{gender},state=#{status},birthday=#{birthday},join_date=#{joinDate},"+
            "telephone=#{telephone} where user_id=#{userId}")
    Boolean updateUser(User user);

    List<User> selectByPage(@Param("state") Integer state, @Param("username") String username);

    Boolean addUserRole(@Param("roleUserVo") RoleUserVo roleUserVo);
}